﻿using MapGeneration;
using PluginAPI.Core;
using System.Linq;
using UnityEngine;


namespace Utils
{
    /// <summary>
    /// 助理 | 出生刷新点
    /// </summary>
    public class SpawnPointUtils
    {
        static Transform HCZCheckpointA;
        static Transform HCZCheckpointB;
        static Transform LCZ330;
        static Transform HCZ096;


        /// <summary>
        /// 
        /// </summary>
        public static bool TryGetHCZCheckpointB(out Transform point)
        {
            RoomIdentifier match = Map.Rooms.ToList().First(room => room.Name == RoomName.HczCheckpointB);

            if (match == null)
            {
                point = match.gameObject.transform;
                return false;
            }

            if (HCZCheckpointB != null)
            {
                point = HCZCheckpointB;
                return true;
            }

            GameObject spawnPoint = new GameObject();
            spawnPoint.transform.parent = match.ApiRoom.GameObject.transform;
            spawnPoint.transform.localPosition = new Vector3(-4f, 1f, -7f);

            point = HCZCheckpointB = spawnPoint.transform;
            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        public static bool TryGetSpawnPoint(RoomName roomName, Vector3 offset, out Vector3 positon)
        {
            RoomIdentifier match = Map.Rooms.ToList().Find(room => room.Name == roomName);
            if (match == null)
            {
                Log.Info($"SpawnPointUtils|获取点无效：{roomName}");
                positon = Vector3.zero;
                return false;
            }

            GameObject spawnPoint = new GameObject();
            spawnPoint.transform.parent = match.ApiRoom.GameObject.transform;
            spawnPoint.transform.localPosition = offset;
            positon = spawnPoint.transform.position;

            return true;
        }
    }
}
